package com.jack.leetcode.pointer;

public class 删除链表的第N个节点 {

    public class ListNode {
        int val;
        ListNode next;
        ListNode(int x) { val = x; }
    }


    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode result = new ListNode(0);
        result.next = head;

        ListNode p = result;
        ListNode q = result;
        while(n!=0){
            q = q.next;
            n--;
        }
        while(q.next != null){
            q = q.next;
            p = p.next;
        }
        p.next = p.next.next;
        return result.next;
    }
}
